/**
 * @date 11:31:59 AM
 * EducationStudentMessageDaoImpl.java
 * Administrator
 * TODO
 */
package com.qs.education.bean.dao.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import com.qs.education.bean.dao.IEducationStudentMessageDao;
import com.qs.education.bean.entity.EducationStudent;
import com.qs.education.bean.entity.EducationStudentMessage;
/**
 * @class EducationStudentMessageDaoImpl	
 * @author Warren
 * @description
 * @date Nov 19, 2018 
 */
@Repository
public class EducationStudentMessageDaoImpl extends BaseDaoImpl<EducationStudentMessage> implements IEducationStudentMessageDao{
	
	/**
	 * @author Warren
	 * @param educationStudent
	 * @return List<EducationStudentMessage>
	 * @description 根据student查询message
	 * @date Nov 12, 2018
	 */
	@Override
	public List<EducationStudentMessage> findListByStudent(EducationStudent educationStudent,int currentPage,int pageSize) {
		String jql = "from EducationStudentMessage em where em.student = :student order by id desc";
		Map<String, Object> params = new HashMap<>();
		params.put("student", educationStudent);
		int firstResult = (currentPage-1)*pageSize;
		List<EducationStudentMessage> result = query(jql, EducationStudentMessage.class, firstResult, pageSize, params);
		if(null != result && !result.isEmpty()){
			return result;
		}
		return null;
	}

	/**
	 * @author Warren
	 * @param educationStuent
	 * @return int
	 * @description 根据student查询message总条数
	 * @date Nov 21, 2018
	 */
	@Override
	public int getALLCountByStudent(EducationStudent educationStudent) {
		String jql = "Select count(*) from EducationStudentMessage em where em.student = :student";
		Query query = em.createQuery(jql);
		query.setParameter("student", educationStudent);
		return ((Long)query.getSingleResult()).intValue();
	}
}
